﻿using AntQuartzUI.Services;
using Quartz;
using Quartz.Listener;

namespace AntQuartzUI;

public class JobExecutionMonitor : JobListenerSupport
{
    private readonly IQuartzService _quartzService;
    
    public JobExecutionMonitor(IQuartzService quartzService)
    {
        _quartzService = quartzService;
    }
    
    public override string Name { get; } = nameof(JobExecutionMonitor);

    public override async Task JobExecutionVetoed(IJobExecutionContext context, CancellationToken cancellationToken = new CancellationToken())
    {
        _quartzService.VetoCountsDic[context.Trigger.Key] = _quartzService.VetoCountsDic.GetOrAdd(context.Trigger.Key, 0) + 1;
        await base.JobExecutionVetoed(context, cancellationToken);
    }
}